package com.lch.mybatis;

import com.lch.mybatis.domain.Blog;
import com.lch.mybatis.mapper.BlogMapper;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author: liuchenhui
 * @create: 2019-05-10 11:32
 **/
public class BlogMapperTest {
    public static void main(String[] args) throws IOException {
        String config = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(config);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
            RowBounds rowBounds = new RowBounds(0, 1);
            final List<Blog> blogs = mapper.selectBlogList(rowBounds);
            System.out.println(blogs);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}